<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root"></div>
    <div>123123</div>
    <div>222</div>
    <script>
        const oRoot = document.getElementById('root')
        
        const oP = document.createElement('p')
        oP.innerHTML = '我是p标签'

        const div = document.createElement('div')
        div.innerHTML = '我是div'

        // oRoot.appendChild(oP)
        // oRoot.appendChild(div)

        // 1. 创建文档碎片
        const fragment = document.createDocumentFragment()
        fragment.appendChild(oP)
        fragment.appendChild(div)

        // 2. 将文档碎片整体放入 root中
        oRoot.appendChild(fragment)

    </script>
</body>
</html>